package freightCalculator;

public class Result {

    float p;
    float s;
    float w;
    public Result(float p, float s, float w){
        this.p=p;
        this.s=s;
        this.w=w;
    }
    public float getDiscountRate(){
        if(s < 250) {
            return 0;
        } else if (s >= 250 && s < 500) {
            return 0.02f;
        } else if (s >= 500 && s < 1000) {
            return 0.05f;
        } else if (s >= 1000 && s < 2000) {
            return 0.08f;
        } else if (s >= 2000 && s < 3000) {
            return 0.10f;
        } else {
            return 0.15f;
        }
    }
    public double calculateFreight(){
        double basicFreight = p * s * w; // 基本运费
        double discountRate = getDiscountRate(); // 根据路程获取折扣率
        return basicFreight * (1 - discountRate);
    }

}
